package newPan3d.content.self
{
	import _Pan3D.core.Mathclass;
	import _Pan3D.display3D.Display3DMovie;
	import _Pan3D.display3D.interfaces.IDisplay3DMovie;
	
	import _me.Scene_data;
	
	import flash.display.Stage;
	import flash.display3D.Context3D;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.geom.Vector3D;
	
	import newPan3d.content.ground.map.MapClass;

	public class SelfDisplay3DMove extends Display3DMovie implements IDisplay3DMovie
	{


		public function SelfDisplay3DMove(context:Context3D)
		{
			super(context);
		}

		private var willStop:Boolean;
		override public function update():void
		{
			super.update();

			var focus3D:SelfDisplay3DMove=this;

			/*
			var nextX:Number=100;
			var nextY:Number=100;
			var angly:Number= Mathclass.math_angle(nextX,nextY,focus3D.x,focus3D.z)
			var d:Number= Mathclass.math_distance(nextX,nextY,focus3D.x,focus3D.z)
			var seepNum:Number=1;
			if(d>1){
				focus3D.x = focus3D.x + seepNum * Math.cos(angly * Math.PI / 180);
				focus3D.z = focus3D.z + seepNum * Math.sin(angly * Math.PI / 180);
				focus3D.rotationY=90-angly;
			}
		*/
			var d:Number;
			var angly:Number;
			var seepNum:Number=1;
			if (_nextPoint)
			{
				d=Mathclass.math_distance(focus3D.x, focus3D.z, _nextPoint.x, _nextPoint.z)
				angly=Mathclass.math_angle(_nextPoint.x, _nextPoint.z, focus3D.x, focus3D.z)
				if (d > 1)
				{

					focus3D.x=focus3D.x + seepNum * Math.cos(angly * Math.PI / 180);
					focus3D.z=focus3D.z + seepNum * Math.sin(angly * Math.PI / 180);
					focus3D.rotationY=-(angly + 90) + 180;

				}
				else
				{
					_nextPoint=null;
					if(willStop){
						trace("233245324534")
						willStop = false
					}
				}
			}
			else
			{
				if (_loadArr && _loadArr.length > 0)
				{
					var k:Vector3D=_loadArr.shift();
					_nextPoint=new Vector3D(k.x , 0, k.z)
					if(_loadArr.length == 0){
						willStop = true;
					}
				}
			}
			Scene_data.focus3D.x=focus3D.x;
			Scene_data.focus3D.z=focus3D.z;
			
		//	var cc:int=MapClass.getMapPixel(Math.round(focus3D.x/2+0.5),Math.round(focus3D.z/2+0.5));
		
	

		}
		private var _loadArr:Vector.<Vector3D>;
		private var _nextPoint:Vector3D;

		public function pushLoadArr(arr:Vector.<Vector3D>):void
		{
			_loadArr=arr;
			_nextPoint=null;
			willStop = false;
		}


	}
}
